<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue中多个元素或组件的过渡</title>
    <script src="./js/vue.js"></script>
    <style>
        .fade-enter, .fade-leave-to{
            opacity: 0;
        }
        .fade-enter-active, .fade-leave-active{
            transition: opacity 1s;
        }
    </style>
</head>
<body>
    <div id="root">
        <transition name="fade" mode="out-in">
            <!-- <div v-if="show" key="hello">hello vue</div>
            <div v-else key="bye">bye vue</div> -->

            <!-- 使用组件进行切换 -->
            <!-- <child v-if="show" key="hello"></child>
            <child-one v-else key="bye"></child-one> -->

            <!-- 使用动态组件 -->
            <component :is="type"></component>
        </transition>
        <button @click="handleBtnClick">切换</button>
    </div>
    <script>
        Vue.component('child', {
            template: `<div>child</div>`
        });
        Vue.component('child-one', {
            template: `<div>child-one</div>`
        })
        var vm = new Vue({
            el: '#root',
            data: {
                show: true,
                type: 'child'
            },
            methods: {
                handleBtnClick: function(){
                    this.show = !this.show;
                    // 动态组件判断
                    this.type = this.type === 'child' ? 'child-one' : 'child';
                }
            }
        });
    </script>
</body>
</html>